package com.atguigu.gmall.payment.receiver;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.payment.service.AlipayService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 关闭 支付信息
 * 关闭 支付宝
 */
@Component
@Slf4j
public class ClosePayment {

    @Autowired
    private AlipayService alipayService;

    //接收消息
    @RabbitListener(queues = MqConst.QUEUE_PAYMENT_CLOSE)
    public void closePaymentMessage(Message message, String orderId, Channel channel) throws Exception {

        log.info("接收订单ID：" + orderId);

        //更新支付信息
        alipayService.closePaymentInfo(orderId);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
